# 要求 PowerShell 5.x/7.x
$dir = $PSScriptRoot
$oldPath = [Environment]::GetEnvironmentVariable('Path', 'User')
if (($oldPath -split ';') -contains $dir) {
    Write-Host "Directory already in PATH, no need to add again."
    exit 0
}
# 拼接并写回用户级 PATH
$newPath = $oldPath + ';' + $dir
[Environment]::SetEnvironmentVariable('Path', $newPath, 'User')
Write-Host "Successfully added to user PATH:"
Write-Host "  $dir"
Write-Host "Please restart your terminal to take effect."